﻿@using Microsoft.AspNet.Identity
@if (Request.IsAuthenticated) {

    //var loginProviders = Context.GetOwinContext().Authentication.User;

    // http://www.itorian.com/2013/11/customize-users-profile-in-aspnet.html
    var userManager = new UserManager<Cdf54.Ja.SignalR.Chat.Models.ApplicationUser>
        (new Microsoft.AspNet.Identity.EntityFramework.UserStore<Cdf54.Ja.SignalR.Chat.Models.ApplicationUser>
            (new Cdf54.Ja.SignalR.Chat.Models.ApplicationDbContext()));

    // Get the current logged in User and look up the user in ASP.NET Identity
    var currentUser = userManager.FindById(User.Identity.GetUserId()); 
        
    //var Db = new Cdf54.Ja.SignalR.Chat.Models.ApplicationDbContext();
    //var user = Db.Users.First(u => u.UserName == User.Identity.Name);
    
    var image = "";

    if (currentUser.PhotoUrl != null)
    {
        image = currentUser.PhotoUrl;
    }
    else
    {
        
        //string vPath = HttpContext.Current.Request.ApplicationPath;
        //image = Path.Combine(vPath, "/Content/Avatars/BlankPhoto.jpg");
        // [10015] PB: Migration files VS dev env
        string vPath = JA.UTILS.Helpers.Utils.AppPath();
        image = vPath + "/Content/Avatars/BlankPhoto.jpg";
        //[10015]
    }
    
    using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" })) {
        @Html.AntiForgeryToken()

    <ul class="nav navbar-nav navbar-right">
        <li>
            <a href="@Url.Action("Index", "Manage")" title="Manage" , rel="nofollow">
                @*[10000] change currentUser.UserName by currentUser.Pseudo*@
                @currentUser.Pseudo <img id="login_photo" class="img-circle" style="float: left; padding-right:5px" height="35" width="35" src="@Url.Content(@image)" />
            </a>
            @*@Html.ActionLink(User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title = "Manage" })*@
        </li>
        <li><a href="javascript:document.getElementById('logoutForm').submit()">Log off</a></li>
    </ul>
    }
}
else
{
    <ul class="nav navbar-nav navbar-right">
        <li>@Html.ActionLink("Register", "Register", "Account", routeValues: null, htmlAttributes: new { id = "registerLink" })</li>
        <li>@Html.ActionLink("Log in", "Login", "Account", routeValues: null, htmlAttributes: new { id = "loginLink" })</li>
    </ul>
}
